package com.future.mayi.fragment;

import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.future.baselib.utils.ToastUtil;
import com.future.mayi.R;
import com.future.mayi.activity.BaseFragment;
import com.future.mayi.model.interfaces.SettingPayPasswordListener;

import butterknife.BindView;
import butterknife.OnClick;

public class SettingPayPasswordFragment extends BaseFragment {


    @BindView(R.id.edt_password)
    EditText edtPassword;
    @BindView(R.id.edt_again_password)
    EditText edtAgainPassword;
    @BindView(R.id.tv_enter)
    TextView tvEnter;

    private SettingPayPasswordListener listener;

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_setting_pay_password;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.tv_enter)
    public void onViewClicked() {


        if (TextUtils.isEmpty(edtPassword.getText())) {
            ToastUtil.getInstance().show(getActivity(), "请输入密码");
            return;
        }
        String passwords = edtPassword.getText().toString();
        if (passwords.length() != 6) {
            ToastUtil.getInstance().show(getActivity(), "请输入正确格式的密码");
            return;
        }


        if (TextUtils.isEmpty(edtAgainPassword.getText())) {
            ToastUtil.getInstance().show(getActivity(), "请再次输入密码");
            return;
        }

        String againPasswords = edtAgainPassword.getText().toString();
        if (againPasswords.length() != 6) {
            ToastUtil.getInstance().show(getActivity(), "请输入正确格式的密码");
            return;
        }


        if (!passwords.equals(againPasswords)) {
            ToastUtil.getInstance().show(getActivity(), "两次输入的密码不一致");
            return;
        }

        if (listener != null)
            listener.enterPassword(passwords, againPasswords);

    }


    public void setListener(SettingPayPasswordListener listener) {
        this.listener = listener;
    }
}
